package org.coding.springbootdemocommandline.fileopr.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import org.coding.springbootdemocommandline.fileopr.data.MockData;
import org.coding.springbootdemocommandline.fileopr.entity.SheetHeaderInfo;
import org.coding.springbootdemocommandline.fileopr.entity.SheetInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

/**
 * ^ enjoy coding and be bugfree boy
 *
 * @author guoxh
 * @date 2020/11/7 3:25 下午
 * @desc
 **/
@Service
public class ExcelOperationServiceImpl {
    @Autowired
    private MockData mockData;

    public void exportExcel(){
        ExcelWriter excelWriter = EasyExcelFactory.write().build();
        SheetInfo sheetInfo = mockData.sheetInfo();
        head(sheetInfo.getHeaderStartColumn(),sheetInfo.getHeaderEndColumn());
        //excelWriter.write();
    }

    public List<List<String>> head(int startColumn,int endColumn){
        List<List<String>> list = new ArrayList<>(endColumn);
        List<SheetHeaderInfo> sheetHeaderInfos = mockData.sheetHeaderInfo();
        for(SheetHeaderInfo sheetHeaderInfo : sheetHeaderInfos){
            List<String> headers = new ArrayList<>();
            int num = sheetHeaderInfo.getHeaderEndColumn() - sheetHeaderInfo.getHeaderStartColumn() ;
            IntStream.range(0,num).forEach( i -> headers.add(sheetHeaderInfo.getHeaderValue()));
            list.add(headers);
        }
        return list;
    }
}
